//
//  HomePageController.m
//  HomePage
//
//  Created by winston on 13-4-10.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "HomePageController.h"
#import "AllAuto_View.h"
#import "../../SecondPage/SecondPage/SecondPageController.h"
#import "../../ResourceLoader/ResourceLoader/ResourceLoader.h"

#import "TemporaryShowView.h"

@interface HomePageController ()

@end

@implementation HomePageController

-(id)initWithFrame:(CGRect)frame
{
    self = [super init];
    if (self)
    {
        self.view.frame = frame;
        
        UIImageView * background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,1024, 768)];
        [self.view addSubview:background];
        [background release];
        [background setImage:[UIImage imageNamed:@"AllAuto_Image_BG"]];
        
        FlowView = [[AllAuto_View alloc] initWithFrame:CGRectMake(0, 0,1024, 768)];
        [self.view addSubview:FlowView];
        [FlowView release];
        
//        showview = [[TemporaryShowView alloc] initWithFrame:CGRectMake(0, 0,1024, 768)];
//        [self.view addSubview:showview];
//        [showview release];
        
        UIButton *  backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 768-60, 56,56)];
        [backBtn setImage:[UIImage imageNamed:@"AllAuto_Button_Home"] forState:UIControlStateNormal];
        [backBtn addTarget:self action:@selector(onBack:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:backBtn];
        [backBtn release];
        

        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onGoSecondPage:) name:Notification_Navigate_SecondPage object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onBackHomePage:) name:Notification_Navigate_FirstHomePage object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onAutosDownloadComplete:) name:@"Notification_DownLoadComplete_Autos" object:nil];
    }
    return self;
}

-(void)onBack:(id)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)onAutosDownloadComplete:(NSNotification*)notify
{
    //[showview RefreshSourceData];
}

-(void)onBackHomePage:(NSNotification*)notify
{
    [self onBack:nil];
}

-(void)onGoSecondPage:(NSNotification*)notify
{
//    NSInteger index = [[notify object]intValue];
//    
//    NSString * autoID = [[[ResourceLoader getInstance]getAutoArray] objectAtIndex:index];
    NSDictionary * dic = [notify object];
    
    SecondPageController * secondPageController = [[SecondPageController alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) AutoInfo:dic];
    [self.navigationController pushViewController:secondPageController animated:NO];
    [secondPageController release];
    //[showview sleep];
}



- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //[showview awakeUp];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 旋转支持

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (BOOL)shouldAutorotate {
    
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    
    return UIInterfaceOrientationMaskLandscape;
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    [super dealloc];
}

#pragma mark -
#pragma mark PagedFlowView Delegate
- (CGSize)sizeForPageInFlowView:(AllAuto_View *)flowView;{
    return CGSizeMake(200, 150);
}


@end
